package com.ysh.contentcenter.sentineltest;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import io.netty.util.internal.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
//@Component
public class MyRequestOriginParser implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest request) {
        // 这里可以获取到request可以通过request来获取请求的origin,如果没有就拒绝访问
        String origin = request.getParameter("origin");
        if(StringUtils.isBlank(origin)){
            throw  new IllegalArgumentException("origin must be specified");
        }
        return origin;
    }
}
